﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

namespace Card.Manager
{
    public partial class AreaManager : BasePage
    {
        #region 属性
        private string m_ProvinceJson = "{}";
        public string ProvinceJson
        {
            get
            {
                return m_ProvinceJson;
            }
        }
        /// <summary>
        /// 地区ID
        /// </summary>
        private int AreaID
        {
            get
            {
                if (Utility.ValidationHelper.IsNumber(this.txtAreaID.Text.Trim()))
                {
                    return int.Parse(this.txtAreaID.Text.Trim());
                }
                return 0;
            }
        }
        
        #endregion

        #region 事件
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.DoInit();
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.btnDelete.Click += new EventHandler(btnDelete_Click);
        }

        void btnDelete_Click(object sender, EventArgs e)
        {
            if (BLL.AreaManager.ExistsChildren(this.AreaID, this.CPassport))
            {
                this.MessageBox("该地区存在子地区，不能删除！");
                return;
            }

            if (BLL.AreaManager.Delete(this.AreaID, this.CPassport))
            {
                this.DoInit();
                this.MessageBox("删除成功！");
            }
        }
             
        #endregion

        #region 方法
        private void DoInit()
        {
            List<Entity.Area> lstArea = BLL.AreaManager.GetListByParentID(0, this.CPassport);
            this.m_ProvinceJson = string.Format("{{'0': {0} }}", Utility.JsonHelper.ObjectListToJson<Entity.Area>(lstArea));

            this.rptProvince.DataSource = lstArea;
            this.rptProvince.DataBind();
        }
        #endregion
    }
}
